package com.dudu.timer;

import java.util.List;

import org.apache.log4j.Logger;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.BeanUtils;

import com.dudu.bean.PushAccountBean;
import com.dudu.dao.AccountExtendDao;
import com.dudu.dao.PushAccountDao;
import com.dudu.model.AccountExtend;
import com.dudu.model.PushAccount;
import com.dudu.utils.ThreadPoolUtils;

import core.CoreDao;
import core.CoreDaoInvoke;
/**
 * 账号合并后向副账号发送主账号信息
 * 线程把accounts进行处理
 *	1、更新主cust_account的几个URL，把副账号的URL送到主的上。
 *	2、根据副账号对应的app_key得到推送地址，进行推送
 *	3、失败，入库等JOB执行
 *	4、成功，入库留做记录
 * @author gaoxs
 * 
 */
public class SendAccountJob implements Job {
	private static final Logger log =  core.util.Logger.getLogger(SendAccountJob.class.getSimpleName());
	private CoreDao dao = CoreDaoInvoke.getInstance();
	private PushAccountDao pushAccountDao=new PushAccountDao();
	private AccountExtendDao accountExtendDao=new AccountExtendDao();
	
	@Override
	public void execute(JobExecutionContext arg0) throws JobExecutionException {
		log.debug("开始定时推送账号任务");
		List<PushAccount> list=pushAccountDao.queryAll(dao);
		for(PushAccount account:list){
			PushAccountBean accountBean=new PushAccountBean();
			BeanUtils.copyProperties(account,accountBean);//源,目的
			AccountExtend ben=accountExtendDao.queryAccountExtendByCustAccount(dao, account.getCust_account());
			accountBean.setKey_public(ben.getKey_public());
			accountBean.setKey_private(ben.getKey_private());
			SendAccountThread accountThreadinfo = new SendAccountThread(dao,accountBean,pushAccountDao);
			ThreadPoolUtils.getThreadPoolUtils().getExecutorService().execute(accountThreadinfo);
		}
	}

}
